package edu.gduf.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.gduf.dao.TeacherMapper;
import edu.gduf.dto.QRCodeDTO;
import edu.gduf.dto.SigninDTO;
import edu.gduf.dto.SigninSystemResult;
import edu.gduf.dto.StuSigninDTO;
import edu.gduf.entity.Signin;
import edu.gduf.entity.Teacher;
import edu.gduf.service.TeacherService;

/**
 * Created by hrm on 2017/4/8.
 */
@Service
public class TeacherServiceImpl implements TeacherService{
    @Autowired
    TeacherMapper teacherMapper;
    @Override
	public Teacher executeLogin(int tId, String tPassword) {
		return teacherMapper.selectByIdAndPassword(tId, tPassword);

    }

    @Override
    public SigninSystemResult updatePassword(int tId, String sPassword, String dPassword) {
        Teacher teacher = teacherMapper.selectByIdAndPassword(tId,sPassword);
        SigninSystemResult signinSystemResult ;
        if(teacher == null) {
            signinSystemResult = new SigninSystemResult(false, "原密码输入错误!");
        } else {
            teacher.settPassword(dPassword);
            int count = teacherMapper.updateByPrimaryKey(teacher);
            if(count == 1) {
                signinSystemResult = new SigninSystemResult(true, "更新密码成功!");
            } else {
                signinSystemResult = new SigninSystemResult(false, "更新密码失败!");
            }
        }
        return signinSystemResult;
    }

    @Override
    public SigninSystemResult updateEmail(int tId, String tEmail) {
        Teacher teacher = teacherMapper.selectById(tId);
        SigninSystemResult signinSystemResult ;
        if(teacher == null) {
            signinSystemResult = new SigninSystemResult(false, "该教师信息不存在!");
        } else {
            teacher.settEmail(tEmail);
            int count = teacherMapper.updateByPrimaryKey(teacher);
            if(count == 1) {
                signinSystemResult = new SigninSystemResult(true, "更新邮箱成功!");
            } else {
                signinSystemResult = new SigninSystemResult(false, "更新邮箱失败!");
            }
        }
        return signinSystemResult;
    }

    @Override
    public List<Signin> getSigninList(Signin signin) {
        return null;
    }

    @Override
    public QRCodeDTO insertSignin(SigninDTO signinDTO) {
        return null;
    }

    @Override
    public SigninSystemResult updateStudentSignin(StuSigninDTO stuSigninDTO) {
        return null;
    }
}
